/**
 * 项目名称:
 *
 * @Author: 夏国倩
 * @Date: 2023/10/10 15:31
 * @Copyright
 */
package IO2;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/*
FileReader:文件字符输入流，只能读取普通文本。读取文本内容，比较方便、快捷
 */
public class FileReaderTest {
    public static void main(String[] args) {
        FileReader reader=null;
        try {
            //创建文件字符输入流
            reader=new FileReader("E:\\code\\TestDemo\\src\\demo\\IO2\\tempfile");

            //准备char数组
            char[] chars=new char[4];
            //往数组中读
            reader.read(chars);
            for (char c:chars){
                System.out.println(c);
            }
            /*//开始读
            char[] chars=new char[4];
            int readCount=0;
            while ((reader.read(chars)) !=-1){
                System.out.println(new String(chars,0,readCount));
            }*/
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (reader !=null){
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
